package com.jzy.controller;

import com.jzy.entity.Vo.UserVo;
import com.jzy.util.MapCache;
import com.jzy.util.TaleUtils;
import org.springframework.ui.Model;

import javax.servlet.http.HttpServletRequest;

public abstract class BaseController {

    protected MapCache cache = MapCache.single();

    public static String THEME = "themes/default";

    /**
     * 获取请求绑定的登录对象
     *
     * @param request
     * @return
     */
    public UserVo user(HttpServletRequest request) {
        return TaleUtils.getLoginUser(request);
    }

    public BaseController title(Model model, String title) {
        model.addAttribute("title", title);
        return this;
    }

    /**
     * 主页的页面主题
     *
     * @param viewName
     * @return
     */
    public String render(String viewName) {
        return THEME + "/" + viewName;
    }

    public Integer getUid(HttpServletRequest request) {
        return this.user(request).getUid();
    }

    public String render_404() {
        return "comm/error_404";
    }

}
